<?php
include('includes/config.php');
include('includes/main_functions.php');

$query = "SELECT e.id, e.message_id, e.email, m.subject, m.message FROM emails AS e, messages AS m WHERE e.message_id=m.id AND e.sent='0' ORDER BY e.id DESC LIMIT 25";
$temp =  sql_query($query);
while($res = sql_fetch_row($temp)) {
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'From: <'. $site['email']. '> ' . "\r\n";
    $headers .= 'X-Mailer: PHP/' . phpversion();

    if(mail($res['email'], $res['subject'], $res['message'], $headers)) {
        echo 'sent to: ',$res['email'].'<br>';
        sql_query("UPDATE emails SET sent='1' WHERE id='".$res['id']."'");
    } else {
        echo 'not sent to: ',$res['email'].'<br>';
    }
    sleep(2);
}
?>